<template>
  <div class="app-container">
    <el-table v-loading="listLoading"
              :data="list"
              element-loading-text="Loading"
              border
              fit
              highlight-current-row
              @row-click="getDetails">
      <el-table-column align="center"
                       label="订单编号"
                       width="170">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="顾客ID"
                       width="170"
                       align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.user_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总价"
                       width="170"
                       align="center">
        <template slot-scope="scope">
          {{ scope.row.total_price }}
        </template>
      </el-table-column>
      <el-table-column class-name="status-col"
                       label="状态"
                       width="170"
                       align="center">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.discount }} 折</el-tag>
        </template>
      </el-table-column>
      <el-table-column align="center"
                       prop="created_at"
                       label="创建时间">
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.add_time }}</span>
        </template>
      </el-table-column>
    </el-table>

    <el-drawer title="我是标题"
               :visible.sync="drawer"
               :with-header="false">
      <div class="block">
        <h2 class="order_title">订单详情</h2>
        <el-timeline>
          <el-timeline-item placement="top"
                            v-for="item in choseOrder"
                            :timestamp="item.add_time"
                            :key="item.id">
            <el-card>
              <h4>{{item.food.name}}</h4>
              <p>{{item.food.desc}}</p>
              <el-button type="success"
                         icon="el-icon-check"
                         circle
                         size="mini"></el-button>
              <el-button type="primary"
                         icon="el-icon-edit"
                         circle
                         size="mini"></el-button>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { GetOrderList } from '@/api/order'

export default {
  data () {
    return {
      list: null,
      listLoading: true,
      drawer: false,
      choseOrder: 0
    }
  },
  created () {
    this.fetchData()
  },
  methods: {
    fetchData () {
      this.listLoading = false
      var that = this;
      GetOrderList(1).then(res => {
        that.list = res.data
      }).catch(err => {
        console.log(err);
      })
    },
    getDetails (row, event, column) {
      this.drawer = true
      console.log(row.order_terms)
      this.choseOrder = row.order_terms
    }
  }
}
</script>

<style>
.block {
  height: 100%;
  padding: 40px 0px;
}
.order_title {
  margin: 40px 20px;
}

.el-drawer__body {
  overflow: auto;
}

.el-drawer__container ::-webkit-scrollbar {
  display: none;
}
</style>>
